<template>
    <div>
        <!--统计信息-->
        <el-row :gutter="10" style="margin-bottom: 60px">
            <el-col :span="6">
                <el-card style="color: #409EFF">
                    <div><i class="el-icon-user-solid" /> 用户总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        100
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #F56C6C">
                    <div><i class="el-icon-money" /> 销售总量</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        ￥ 1000000
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #67C23A">
                    <div><i class="el-icon-bank-card" /> 收益总额</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        ￥ 300000
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #E6A23C">
                    <div><i class="el-icon-s-shop" /> 门店总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold">
                        20
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <div id="main" style="width: 500px; height: 400px"></div>
            </el-col>

            <el-col :span="12">
                <div id="pie" style="width: 500px; height: 400px"></div>
            </el-col>
        </el-row>

    </div>
</template>

<script>
    import * as echarts from 'echarts'

    export default {
        name: "Home",
        data() {
            return {

            }
        },
        mounted() {  // 页面元素渲染之后再触发
            //柱线配置项
            var option = {
                //标题
                title: {
                    text: '各季度会员数量统计',
                    subtext: '趋势图',
                    left: 'center'
                },
                //工具提示
                tooltip: {
                    //经过显示
                    trigger: 'item'
                },
                //显示左上角标志
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                //横坐标
                xAxis: {
                    type: 'category',
                    data: ["第一季度", "第二季度", "第三季度", "第四季度"]
                },
                yAxis: {
                    type: 'value'
                },
                //系列
                series: [
                    //线
                    {
                        name: "java",
                        // 填充的数据
                        data: [],
                        type: 'line'
                    },
                    //柱形
                    {
                        name: "java",
                        data: [],
                        type: 'bar'
                    },

                    //线
                    {
                        name: "c++",
                        // 填充的数据
                        data: [],
                        type: 'line'
                    },
                    //柱形
                    {
                        name: "c++",
                        data: [],
                        type: 'bar'
                    }
                ]
            };

            // 饼图配置项

            var pieOption = {
                title: {
                    text: '各季度会员数量统计',
                    subtext: '比例图',
                    left: 'center'
                },
                // 工具提示
                tooltip: {
                    //鼠标经过
                    trigger: 'item',
                    //格式化  a:标题    b；季度 c:数量 d:百分比
                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: "java",
                        type: 'pie',
                        //大小
                        radius: '60%',
                        // 中心位置
                        center: ['25%', '70%'],
                        //默认显示
                        label:{            //饼图图形上的文本标签
                            normal:{
                                show:true,
                                position:'inner', //标签的位置，内部
                                textStyle : {
                                    fontWeight : 300 ,
                                    fontSize : 14,    //文字的字体大小
                                    color: "#fff"
                                },
                                //格式化
                                formatter:'{c}：({d}%)'
                            }
                        },
                        data: [],  // 填空
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    },

                    {
                        name: "c++",
                        type: 'pie',
                        //大小
                        radius: '50%',
                        //位置
                        center: ['75%', '50%'],
                        label:{            //饼图图形上的文本标签
                            normal:{
                                show:true,
                                position:'inner', //标签的位置
                                textStyle : {
                                    fontWeight : 300 ,
                                    fontSize : 14,    //文字的字体大小
                                    color: "#fff"
                                },
                                formatter:'{d}%'
                            }
                        },
                        data: [
                            {name: "第一季度", value: 5},
                            {name: "第二季度", value: 6},
                            {name: "第三季度", value: 7},
                            {name: "第四季度", value: 8}
                        ],  // 填空
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            //1. 获取容器
            var chartDom = document.getElementById('main');
            //2. 初始化容器
            var myChart = echarts.init(chartDom);

            var pieDom = document.getElementById('pie');
            var pieChart = echarts.init(pieDom);

            this.request.get("/echarts/members").then(res => {
                // 设置柱跟线
                option.series[0].data = res.data
                option.series[1].data = res.data
                //伪造数据
                option.series[2].data = [3,4,5,6]
                option.series[3].data = [3,4,5,6]



                pieOption.series[0].data = [
                    {name: "第一季度", value: res.data[0]},
                    {name: "第二季度", value: res.data[1]},
                    {name: "第三季度", value: res.data[2]},
                    {name: "第四季度", value: res.data[3]},
                ]

                // 3. 容器初始化配置项
                myChart.setOption(option);
                pieChart.setOption(pieOption)

            })




        }
    }
</script>

<style scoped>

</style>
